package com.ruoyi.system.outto.game.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.system.model.domain.AccountInfo;
import com.ruoyi.system.model.domain.InfoImg;
import com.ruoyi.system.model.domain.SalePartner;
import com.ruoyi.system.model.mapper.AccountInfoMapper;
import com.ruoyi.system.model.mapper.InfoImgMapper;
import com.ruoyi.system.model.mapper.SuprAuthMapper;
import com.ruoyi.system.model.service.impl.AccountInfoServiceImpl;
import com.ruoyi.system.outto.core.*;
import com.ruoyi.system.outto.dto.KghAttribute;
import com.ruoyi.system.outto.dto.KghImg;
import com.ruoyi.system.outto.game.CommonApi;
import com.ruoyi.system.outto.game.KANGEHAOAPI;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author lz
 * @version 1.0
 * @date 2022/6/5 16:19
 */
@Slf4j
@Service
public class KANGEHAOImpl implements KANGEHAOAPI {

    @Resource
    private InfoImgMapper infoImgMapper;
    @Resource
    private SuprAuthMapper suprAuthMapper;
    @Resource
    private CommonApi commonApi;
    @Value("${desc.title}")
    private String descTitle;
    private SalePartner salePartner;
    @Resource
    private AccountInfoMapper accountInfoMapper;

    @Override
    public AjaxResult addGame(AccountInfo accountInfo, Long userId,SalePartner salePartner) {
        this.salePartner = salePartner;
        Map<String, Object> result = new HashMap<>();
        Map<String, Object> params = params(accountInfo, "add");
        Map<String, Object> canshu = new HashMap<>();
        String uuid = UUID.fastUUID().toString();
        String timestamp = String.valueOf(new Date().getTime()/1000);
        String md5 = DigestUtils.md5Hex(salePartner.getOther()+salePartner.getSaleKey()+timestamp+uuid).toUpperCase();
        canshu.put("x-kgh-token",salePartner.getOther());
        canshu.put("x-kgh-nonce",uuid);
        canshu.put("x-kgh-signature",md5);
        canshu.put("x-kgh-timestamp",timestamp);
        log.info("看个号添加接口请求参数={}", JSONObject.toJSONString(params));
        String response = HttpUtils.sendPostAddHeader(salePartner.getTwoOther()+"/publishGoods", JSONObject.toJSONString(params),canshu);
        log.info("看个号添加接口返回参数={}", response);
        JSONObject resultJson = JSONObject.parseObject(response);
        if (!"SUCCESS".equals(resultJson.getString("code"))) {
            result.put("code", 500);
        } else {
            result.put("code", 200);
            String kangehaoid = resultJson.getString("data");
            JSONObject jsonObject = JSONObject.parseObject(kangehaoid);
            AccountInfo info = accountInfoMapper.selectAccountInfoById(accountInfo.getId());
            info.setKangehaoid(jsonObject.getString("guid"));
            accountInfoMapper.updateAccountInfo(info);
        }

        result.put("req", JSONObject.toJSONString(params));
        result.put("res", response);
        result.put("msg", resultJson.getString("data"));
        return AjaxResult.success(result);
    }

    @Override
    public AjaxResult editGame(AccountInfo accountInfo, Long userId,SalePartner salePartner) {
        this.salePartner = salePartner;
        Map<String, Object> result = new HashMap<>();
        Map<String, Object> params = params(accountInfo, "edit");
        Map<String, Object> canshu = new HashMap<>();
        String uuid = UUID.fastUUID().toString();
        String timestamp = String.valueOf(new Date().getTime()/1000);
        String md5 = DigestUtils.md5Hex(salePartner.getOther()+salePartner.getSaleKey()+timestamp+uuid).toUpperCase();
        canshu.put("x-kgh-token",salePartner.getOther());
        canshu.put("x-kgh-nonce",uuid);
        canshu.put("x-kgh-signature",md5);
        canshu.put("x-kgh-timestamp",timestamp);
        log.info("看个号编辑接口请求参数={}", JSONObject.toJSONString(params));
        String response = HttpUtils.sendPostAddHeader(salePartner.getTwoOther()+"/editGoods", JSONObject.toJSONString(params), canshu);
        log.info("看个号编辑接口返回参数={}", response);
        JSONObject resultJson = JSONObject.parseObject(response);

        if (!"SUCCESS".equals(resultJson.getString("code"))) {
            result.put("code", 500);
        } else {
            result.put("code", 200);
        }

        result.put("req", JSONObject.toJSONString(params));
        result.put("res", response);
        result.put("msg", resultJson.getString("data"));
        return AjaxResult.success(result);
    }

    private Map<String, Object> params(AccountInfo accountInfo, String type) {
        Map<String, Object> params = new HashMap<>();
        if(type.equals("add")) {
            params.put("partner_number", String.valueOf(accountInfo.getId()));
            JSONArray youxizhanghao = JSONObject.parseArray(KGHConstant.youxizhanghao);
            for (Object o : youxizhanghao) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if (accountInfo.getType().replace("CF端游", "穿越火线").replace("CF手游", "枪战王者")
                        .equals(jsonObject1.getString("game_name"))) {
                    params.put("category_id", Integer.parseInt(jsonObject1.getString("id")));
                    break;
                }
            }
        }else{
            params.put("guid", Long.valueOf(accountInfo.getKangehaoid()));
        }
        String des = accountInfo.getDes().length()>90?accountInfo.getDes().substring(0,50):accountInfo.getDes();
        params.put("goods_title", descTitle+accountInfo.getId()+des);
        params.put("goods_describe", accountInfo.getDes());
        BigDecimal bigDecimal = commonApi.addPrice(accountInfo.getPrice(), salePartner.getSeleep());
        commonApi.setPrice(bigDecimal,accountInfo.getId(),salePartner);
        params.put("price", bigDecimal);
        params.put("thumb_url", accountInfo.getTitleImg());
        InfoImg infoImg = new InfoImg();
        infoImg.setInfoId(accountInfo.getId());
        infoImg.setType(Constants.STR_1);
        List<InfoImg> infoImgs = infoImgMapper.selectInfoImgList(infoImg);
        List<KghImg> images = new ArrayList<>();
        for(int i = 0;i<infoImgs.size();i++){
            KghImg kghImg = new KghImg();
            kghImg.setImg_url(infoImgs.get(i).getImgUrl());
            kghImg.setThumb_img_url(infoImgs.get(i).getImgUrl());
            images.add(kghImg);
        }
        params.put("images", images);
        List<Object> attributes = new ArrayList<>();
        KghAttribute kghAttribute1 = new KghAttribute();
        KghAttribute kghAttribute2 = new KghAttribute();
        KghAttribute kghAttribute3 = new KghAttribute();
        KghAttribute kghAttribute4 = new KghAttribute();
        KghAttribute kghAttribute5 = new KghAttribute();
        KghAttribute kghAttribute6 = new KghAttribute();
        KghAttribute kghAttribute7 = new KghAttribute();
        KghAttribute kghAttribute8 = new KghAttribute();
        KghAttribute kghAttribute9 = new KghAttribute();
        KghAttribute kghAttribute10 = new KghAttribute();
        KghAttribute kghAttribute11 = new KghAttribute();
        KghAttribute kghAttribute12 = new KghAttribute();
        KghAttribute kghAttribute13 = new KghAttribute();
        KghAttribute kghAttribute14 = new KghAttribute();
        KghAttribute kghAttribute15 = new KghAttribute();
        KghAttribute kghAttribute16 = new KghAttribute();
        KghAttribute kghAttribute17 = new KghAttribute();
        KghAttribute kghAttribute18 = new KghAttribute();
        KghAttribute kghAttribute19 = new KghAttribute();
        KghAttribute kghAttribute20= new KghAttribute();
        KghAttribute kghAttribute21= new KghAttribute();
        KghAttribute kghAttribute22= new KghAttribute();
        KghAttribute kghAttribute23= new KghAttribute();
        if(accountInfo.getType().equals("王者荣耀")){
            //王者荣耀
            if (Arrays.asList(LCConstant.haveTwoList).contains(accountInfo.getLevel())){
                kghAttribute1.setAttribute_id(36);
                kghAttribute1.setAttribute_id(36);
                kghAttribute1.setOption_value("2");
            }
            if(LCConstant.noTwo.equals(accountInfo.getLevel())){
                kghAttribute1.setAttribute_id(36);
                kghAttribute1.setOption_value("5");
            }
            if(Objects.equals(LCConstant.bakFace,accountInfo.getLevel())||Objects.equals(LCConstant.rezhengMial,accountInfo.getLevel())){
                kghAttribute1.setAttribute_id(36);
                kghAttribute1.setOption_value("4");
            }
            JSONArray youxiqufu = JSONObject.parseArray(KGHConstant.youxiqufu);
            for (Object o : youxiqufu) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(jsonObject1.getString("service_name").contains(accountInfo.getRegional().replace("WX","VX"))){
                    params.put("client_id",Integer.parseInt(jsonObject1.getString("id")));
                    break;
                }
            }
            JSONArray guizudengji = JSONObject.parseArray(KGHConstant.guizudengji);
            for (Object o : guizudengji) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name").replace("V","贵族"))){
                    kghAttribute2.setAttribute_id(Integer.parseInt(jsonObject1.getString("attribute_id")));
                    kghAttribute2.setOption_value(jsonObject1.getString("option_value"));
                    break;
                }
            }
            kghAttribute3.setAttribute_id(39);
            kghAttribute3.setOption_value(accountInfo.getHeroes().toString());
            kghAttribute4.setAttribute_id(40);
            kghAttribute4.setOption_value(accountInfo.getSkins().toString());
            JSONArray rongyaodiancang = JSONObject.parseArray(KGHConstant.rongyaodiancang);
            String optionValue = "";
            for (Object o : rongyaodiancang) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    optionValue += ","+jsonObject1.getString("option_value");
                }
            }
            String string = null;
            if(StringUtils.isNotEmpty(optionValue)) {
                string = optionValue.substring(1);
                kghAttribute5.setAttribute_id(42);
                kghAttribute5.setOption_value(string);
            }
            JSONArray xingchuanshuo = JSONObject.parseArray(KGHConstant.xingchuanshuo);
            String xingchuanshuoValue = "";
            for (Object o : xingchuanshuo) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    xingchuanshuoValue += ","+jsonObject1.getString("option_value");
                }
            }
            String xingchuanshuoString = null;
            if(StringUtils.isNotEmpty(xingchuanshuoString)){
                xingchuanshuoString = xingchuanshuoValue.substring(1);
                kghAttribute6.setAttribute_id(53);
                kghAttribute6.setOption_value(xingchuanshuoString);
            }
            JSONArray chuanshuopifu = JSONObject.parseArray(KGHConstant.chuanshuopifu);
            String chuanshuopifuValue = "";
            for (Object o : chuanshuopifu) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    chuanshuopifuValue += ","+jsonObject1.getString("option_value");
                }
            }
            String chuanshuopifuString = null;
            if(StringUtils.isNotEmpty(chuanshuopifuValue)) {
                chuanshuopifuString = chuanshuopifuValue.substring(1);
                kghAttribute7.setAttribute_id(43);
                kghAttribute7.setOption_value(chuanshuopifuString);
            }
            JSONArray xiandingpifu = JSONObject.parseArray(KGHConstant.xiandingpifu);
            String xiandingpifuValue = "";
            for (Object o : xiandingpifu) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    xiandingpifuValue += ","+jsonObject1.getString("option_value");
                }
            }
            String xiandingpifuString = null;
            if(StringUtils.isNotEmpty(xiandingpifuValue)) {
                xiandingpifuString = xiandingpifuValue.substring(1);
                kghAttribute8.setAttribute_id(52);
                kghAttribute8.setOption_value(xiandingpifuString);
            }
            JSONArray shishipifu = JSONObject.parseArray(KGHConstant.shishipifu);
            String shishipifuValue = "";
            for (Object o : shishipifu) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    shishipifuValue += ","+jsonObject1.getString("option_value");
                }
            }
            String shishipifuString = null;
            if(StringUtils.isNotEmpty(shishipifuValue)) {
                shishipifuString = shishipifuValue.substring(1);
                kghAttribute9.setAttribute_id(44);
                kghAttribute9.setOption_value(shishipifuString);
            }
            if(Objects.equals(LCConstant.bakFace,accountInfo.getLevel())){
                kghAttribute10.setAttribute_id(217);
                kghAttribute10.setOption_value("2");
            }else{
                kghAttribute10.setAttribute_id(217);
                kghAttribute10.setOption_value("3");
            }
            kghAttribute11.setAttribute_id(226);
            kghAttribute11.setOption_value("3");
        }
        if(accountInfo.getType().equals("和平精英")){
            //和平精英
            JSONArray youxiqufu = JSONObject.parseArray(KGHConstant.hepingqufu);
            for (Object o : youxiqufu) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(jsonObject1.getString("service_name").contains(accountInfo.getRegional().replace("WX","微信"))){
                    params.put("client_id",Integer.parseInt(jsonObject1.getString("id")));
                    break;
                }
            }
            //有二次/无二次
            if (Arrays.asList(LCConstant.haveTwoList).contains(accountInfo.getLevel())){
                kghAttribute1.setAttribute_id(102);
                kghAttribute1.setOption_value("2");
            }
            if(LCConstant.noTwo.equals(accountInfo.getLevel())){
                kghAttribute1.setAttribute_id(102);
                kghAttribute1.setOption_value("4");
            }
            if(Objects.equals(LCConstant.bakFace,accountInfo.getLevel())||Objects.equals(LCConstant.rezhengMial,accountInfo.getLevel())){
                kghAttribute1.setAttribute_id(102);
                kghAttribute1.setOption_value("6");
            }
            //枪械数量
            kghAttribute2.setAttribute_id(103);
            kghAttribute2.setOption_value(accountInfo.getGuns().toString());
            //时装数量
            kghAttribute3.setAttribute_id(104);
            kghAttribute3.setOption_value(accountInfo.getSuit().toString());
            //载具数量
            kghAttribute4.setAttribute_id(105);
            kghAttribute4.setOption_value("0");
            //战备数量
            kghAttribute5.setAttribute_id(106);
            kghAttribute5.setOption_value("0");
            //稀有枪皮
            JSONArray xiyouqiangpi = JSONObject.parseArray(KGHConstant.xiyouqiangpi);
            String xiyouqiangpiValue = "";
            for (Object o : xiyouqiangpi) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    xiyouqiangpiValue += ","+jsonObject1.getString("option_value");
                }
            }
            String xiyouqiangpiString = null;
            if(StringUtils.isNotEmpty(xiyouqiangpiValue)) {
                xiyouqiangpiString = xiyouqiangpiValue.substring(1);
                kghAttribute6.setAttribute_id(107);
                kghAttribute6.setOption_value(xiyouqiangpiString);
            }
            //优质枪皮
            JSONArray youzhiqiangpi = JSONObject.parseArray(KGHConstant.youzhiqiangpi);
            String youzhiqiangpiValue = "";
            for (Object o : youzhiqiangpi) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    youzhiqiangpiValue += ","+jsonObject1.getString("option_value");
                }
            }
            String youzhiqiangpiString = null;
            if(StringUtils.isNotEmpty(youzhiqiangpiValue)) {
                youzhiqiangpiString = youzhiqiangpiValue.substring(1);
                kghAttribute7.setAttribute_id(125);
                kghAttribute7.setOption_value(youzhiqiangpiString);
            }
            //稀有套装
            JSONArray xiyoutaozhuang = JSONObject.parseArray(KGHConstant.xiyoutaozhuang);
            String xiyoutaozhuangValue = "";
            for (Object o : xiyoutaozhuang) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    xiyoutaozhuangValue += ","+jsonObject1.getString("option_value");
                }
            }
            String xiyoutaozhuangString = null;
            if(StringUtils.isNotEmpty(xiyoutaozhuangValue)) {
                xiyoutaozhuangString = xiyoutaozhuangValue.substring(1);
                kghAttribute8.setAttribute_id(128);
                kghAttribute8.setOption_value(xiyoutaozhuangString);
            }
            //优质套装
            JSONArray youzhitaozhuang = JSONObject.parseArray(KGHConstant.youzhitaozhuang);
            String youzhitaozhuangValue = "";
            for (Object o : youzhitaozhuang) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    youzhitaozhuangValue += ","+jsonObject1.getString("option_value");
                }
            }
            String youzhitaozhuangString = null;
            if(StringUtils.isNotEmpty(youzhitaozhuangValue)) {
                youzhitaozhuangString = youzhitaozhuangValue.substring(1);
                kghAttribute9.setAttribute_id(130);
                kghAttribute9.setOption_value(youzhitaozhuangString);
            }
            //载具皮肤
            JSONArray zaijupifu = JSONObject.parseArray(KGHConstant.zaijupifu);
            String zaijupifuValue = "";
            for (Object o : zaijupifu) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    zaijupifuValue += ","+jsonObject1.getString("option_value");
                }
            }
            String zaijupifuString = null;
            if(StringUtils.isNotEmpty(zaijupifuValue)) {
                zaijupifuString = zaijupifuValue.substring(1);
                kghAttribute10.setAttribute_id(131);
                kghAttribute10.setOption_value(zaijupifuString);
            }
            //优质降落伞
            JSONArray youzhijiangluosan = JSONObject.parseArray(KGHConstant.youzhijiangluosan);
            String youzhijiangluosanValue = "";
            for (Object o : youzhijiangluosan) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    youzhijiangluosanValue += ","+jsonObject1.getString("option_value");
                }
            }
            String youzhijiangluosanString = null;
            if(StringUtils.isNotEmpty(youzhijiangluosanValue)) {
                youzhijiangluosanString = youzhijiangluosanValue.substring(1);
                kghAttribute11.setAttribute_id(132);
                kghAttribute11.setOption_value(youzhijiangluosanString);
            }
            //优质背包
            JSONArray youzhibeibao = JSONObject.parseArray(KGHConstant.youzhibeibao);
            String youzhibeibaoValue = "";
            for (Object o : youzhibeibao) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    youzhibeibaoValue += ","+jsonObject1.getString("option_value");
                }
            }
            String youzhibeibaoString = null;
            if(StringUtils.isNotEmpty(youzhibeibaoValue)) {
                youzhibeibaoString = youzhibeibaoValue.substring(1);
                kghAttribute12.setAttribute_id(133);
                kghAttribute12.setOption_value(youzhibeibaoString);
            }
            //飞行器
            JSONArray feixingqi = JSONObject.parseArray(KGHConstant.feixingqi);
            String feixingqiValue = "";
            for (Object o : feixingqi) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    feixingqiValue += ","+jsonObject1.getString("option_value");
                }
            }
            String feixingqiString = null;
            if(StringUtils.isNotEmpty(feixingqiValue)) {
                feixingqiString = feixingqiValue.substring(1);
                kghAttribute12.setAttribute_id(134);
                kghAttribute12.setOption_value(feixingqiString);
            }
            if(Objects.equals(LCConstant.bakFace,accountInfo.getLevel())){
                kghAttribute13.setAttribute_id(220);
                kghAttribute13.setOption_value("2");
            }else{
                kghAttribute13.setAttribute_id(220);
                kghAttribute13.setOption_value("3");
            }
            kghAttribute14.setAttribute_id(229);
            kghAttribute14.setOption_value("3");
        }
        if(accountInfo.getType().equals("CF端游")){
            //穿越火线
            //有二次/无二次
            if (Arrays.asList(LCConstant.haveTwoList).contains(accountInfo.getLevel())){
                kghAttribute1.setAttribute_id(135);
                kghAttribute1.setOption_value("2");
            }
            if(LCConstant.noTwo.equals(accountInfo.getLevel())){
                kghAttribute1.setAttribute_id(135);
                kghAttribute1.setOption_value("4");
            }
            if(Objects.equals(LCConstant.bakFace,accountInfo.getLevel())||Objects.equals(LCConstant.rezhengMial,accountInfo.getLevel())){
                kghAttribute1.setAttribute_id(135);
                kghAttribute1.setOption_value("6");
            }
            //账号来源 本人注册 2 平台购买 3 他人赠送 4
            kghAttribute2.setAttribute_id(136);
            kghAttribute2.setOption_value("2");
            //游戏大区
            JSONArray youxiqufu = JSONObject.parseArray(KGHConstant.cfdaqu);
            for (Object o : youxiqufu) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                //if(accountInfo.getRegional().contains("东部")||accountInfo.getRegional().contains("西部")){
                    if(accountInfo.getRegional().replace("大","战").contains(jsonObject1.getString("service_name"))){
                        params.put("client_id",Integer.parseInt(jsonObject1.getString("id")));
                    }
                //}else{
                    /*if(accountInfo.getRegional().replace("部","方").contains(jsonObject1.getString("service_name"))){
                        params.put("client_id",Integer.parseInt(jsonObject1.getString("id")));
                    }*/
                //}
                JSONArray youxiqufu1 = JSONObject.parseArray(jsonObject1.getString("children"));
                for (Object p : youxiqufu1){
                    JSONObject jsonObject2 = JSONObject.parseObject(JSONObject.toJSONString(p));

                    if(accountInfo.getDes().replace("1","一").replace("2","二")
                            .replace("3","三").replace("4","四").contains(jsonObject2.getString("service_name"))){
                        params.put("server_id",Integer.parseInt(jsonObject2.getString("id")));
                    }
                }
            }
            //可排位
            kghAttribute3.setAttribute_id(139);
            kghAttribute3.setOption_value("2");
            //是否禁言 2 禁言 3 无禁言
            kghAttribute4.setAttribute_id(140);
            kghAttribute4.setOption_value("3");
            //王者武器
            JSONArray cfwangzhewuqi = JSONObject.parseArray(KGHConstant.cfwangzhewuqi);
            String cfwangzhewuqiValue = "";
            for (Object o : cfwangzhewuqi) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    cfwangzhewuqiValue += ","+jsonObject1.getString("option_value");
                }
            }
            String cfwangzhewuqiString = null;
            if(StringUtils.isNotEmpty(cfwangzhewuqiValue)) {
                cfwangzhewuqiString = cfwangzhewuqiValue.substring(1);
                kghAttribute5.setAttribute_id(149);
                kghAttribute5.setOption_value(cfwangzhewuqiString);
            }
            //传说级别
            JSONArray cfchuanshuojibie = JSONObject.parseArray(KGHConstant.cfchuanshuojibie);
            String cfchuanshuojibieValue = "";
            for (Object o : cfchuanshuojibie) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    cfchuanshuojibieValue += ","+jsonObject1.getString("option_value");
                }
            }
            String cfchuanshuojibieString = null;
            if(StringUtils.isNotEmpty(cfchuanshuojibieValue)) {
                cfchuanshuojibieString = cfchuanshuojibieValue.substring(1);
                kghAttribute6.setAttribute_id(151);
                kghAttribute6.setOption_value(cfchuanshuojibieString);
            }
            //热门武器
            JSONArray cfremenwuqi = JSONObject.parseArray(KGHConstant.cfremenwuqi);
            String cfremenwuqiValue = "";
            for (Object o : cfremenwuqi) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    cfremenwuqiValue += ","+jsonObject1.getString("option_value");
                }
            }
            String cfremenwuqiString = null;
            if(StringUtils.isNotEmpty(cfremenwuqiValue)) {
                cfremenwuqiString = cfremenwuqiValue.substring(1);
                kghAttribute7.setAttribute_id(152);
                kghAttribute7.setOption_value(cfremenwuqiString);
            }
            //套装效果
            JSONArray cftaozhuangxiaoguo = JSONObject.parseArray(KGHConstant.cftaozhuangxiaoguo);
            String cftaozhuangxiaoguoValue = "";
            for (Object o : cftaozhuangxiaoguo) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    cftaozhuangxiaoguoValue += ","+jsonObject1.getString("option_value");
                }
            }
            String cftaozhuangxiaoguoString = null;
            if(StringUtils.isNotEmpty(cftaozhuangxiaoguoValue)) {
                cftaozhuangxiaoguoString = cftaozhuangxiaoguoValue.substring(1);
                kghAttribute8.setAttribute_id(153);
                kghAttribute8.setOption_value(cftaozhuangxiaoguoString);
            }
            //小人枪
            JSONArray cfxiaorenqiang = JSONObject.parseArray(KGHConstant.cfxiaorenqiang);
            String cfxiaorenqiangValue = "";
            for (Object o : cfxiaorenqiang) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    cfxiaorenqiangValue += ","+jsonObject1.getString("option_value");
                }
            }
            String cfxiaorenqiangString = null;
            if(StringUtils.isNotEmpty(cfxiaorenqiangValue)) {
                cfxiaorenqiangString = cfxiaorenqiangValue.substring(1);
                kghAttribute9.setAttribute_id(154);
                kghAttribute9.setOption_value(cfxiaorenqiangString);
            }
            //稀有角色
            JSONArray cfxiyoujuese = JSONObject.parseArray(KGHConstant.cfxiyoujuese);
            String cfxiyoujueseValue = "";
            for (Object o : cfxiyoujuese) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    cfxiyoujueseValue += ","+jsonObject1.getString("option_value");
                }
            }
            String cfxiyoujueseString = null;
            if(StringUtils.isNotEmpty(cfxiyoujueseValue)) {
                cfxiyoujueseString = cfxiyoujueseValue.substring(1);
                kghAttribute10.setAttribute_id(155);
                kghAttribute10.setOption_value(cfxiyoujueseString);
            }
            //热门道具
            JSONArray cfremendaoju = JSONObject.parseArray(KGHConstant.cfremendaoju);
            String cfremendaojuValue = "";
            for (Object o : cfremendaoju) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    cfremendaojuValue += ","+jsonObject1.getString("option_value");
                }
            }
            String cfremendaojuString = null;
            if(StringUtils.isNotEmpty(cfremendaojuValue)) {
                cfremendaojuString = cfremendaojuValue.substring(1);
                kghAttribute11.setAttribute_id(157);
                kghAttribute11.setOption_value(cfremendaojuString);
            }
            //稀有皮肤
            JSONArray cfxiyoupifu = JSONObject.parseArray(KGHConstant.cfxiyoupifu);
            String cfxiyoupifuValue = "";
            for (Object o : cfxiyoupifu) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    cfxiyoupifuValue += ","+jsonObject1.getString("option_value");
                }
            }
            String cfxiyoupifuString = null;
            if(StringUtils.isNotEmpty(cfxiyoupifuValue)) {
                cfxiyoupifuString = cfxiyoupifuValue.substring(1);
                kghAttribute12.setAttribute_id(157);
                kghAttribute12.setOption_value(cfxiyoupifuString);
            }
            if(Objects.equals(LCConstant.bakFace,accountInfo.getLevel())){
                kghAttribute13.setAttribute_id(218);
                kghAttribute13.setOption_value("2");
            }else{
                kghAttribute13.setAttribute_id(218);
                kghAttribute13.setOption_value("3");
            }
            kghAttribute14.setAttribute_id(227);
            kghAttribute14.setOption_value("3");
        }
        if(accountInfo.getType().equals("CF手游")){
            //枪战王者
            //游戏区服
            JSONArray youxiqufu = JSONObject.parseArray(KGHConstant.cfshouyouqufu);
            for (Object o : youxiqufu) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(jsonObject1.getString("service_name").contains(accountInfo.getRegional().replace("WX","vx"))){
                    params.put("client_id",Integer.parseInt(jsonObject1.getString("id")));
                    break;
                }
            }
            //有二次/无二次
            if (Arrays.asList(LCConstant.haveTwoList).contains(accountInfo.getLevel())){
                kghAttribute1.setAttribute_id(108);
                kghAttribute1.setOption_value("2");
            }
            if(LCConstant.noTwo.equals(accountInfo.getLevel())){
                kghAttribute1.setAttribute_id(108);
                kghAttribute1.setOption_value("5");
            }
            if(Objects.equals(LCConstant.bakFace,accountInfo.getLevel())||Objects.equals(LCConstant.rezhengMial,accountInfo.getLevel())){
                kghAttribute1.setAttribute_id(108);
                kghAttribute1.setOption_value("4");
            }
            //VIP等级
            JSONArray cfvipdengji = JSONObject.parseArray(KGHConstant.cfvipdengji);
            for (Object o : cfvipdengji) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name").replace("V","贵族"))){
                    kghAttribute2.setAttribute_id(Integer.parseInt(jsonObject1.getString("attribute_id")));
                    kghAttribute2.setOption_value(jsonObject1.getString("option_value"));
                    break;
                }
            }
            /*//英雄武器数
            kghAttribute3.setAttribute_id(110);
            kghAttribute3.setOption_value("===============");
            //王者武器数
            kghAttribute4.setAttribute_id(111);
            kghAttribute4.setOption_value("===============");*/
            //角色
            JSONArray cfjuese = JSONObject.parseArray(KGHConstant.cfjuese);
            String cfjueseValue = "";
            for (Object o : cfjuese) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    cfjueseValue += ","+jsonObject1.getString("option_value");
                }
            }
            String cfjueseString = null;
            if(StringUtils.isNotEmpty(cfjueseValue)) {
                cfjueseString = cfjueseValue.substring(1);
                kghAttribute3.setAttribute_id(112);
                kghAttribute3.setOption_value(cfjueseString);
            }
            /*//王者至尊套数量
            kghAttribute6.setAttribute_id(113);
            kghAttribute6.setOption_value("===========================");*/
            //至尊套装
            JSONArray cfsyzhizuntao = JSONObject.parseArray(KGHConstant.cfsyzhizuntao);
            String cfsyzhizuntaoValue = "";
            for (Object o : cfsyzhizuntao) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    cfsyzhizuntaoValue += ","+jsonObject1.getString("option_value");
                }
            }
            String cfsyzhizuntaoString = null;
            if(StringUtils.isNotEmpty(cfsyzhizuntaoValue)) {
                cfsyzhizuntaoString = cfsyzhizuntaoValue.substring(1);
                kghAttribute4.setAttribute_id(114);
                kghAttribute4.setOption_value(cfsyzhizuntaoString);
            }
            //热门套装
            JSONArray cfsyrementao = JSONObject.parseArray(KGHConstant.cfsyrementao);
            String cfsyrementaoValue = "";
            for (Object o : cfsyrementao) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    cfsyrementaoValue += ","+jsonObject1.getString("option_value");
                }
            }
            String cfsyrementaoString = null;
            if(StringUtils.isNotEmpty(cfsyrementaoValue)) {
                cfsyrementaoString = cfsyrementaoValue.substring(1);
                kghAttribute5.setAttribute_id(115);
                kghAttribute5.setOption_value(cfsyrementaoString);
            }
            //王者武器
            JSONArray cfsywangzhewq = JSONObject.parseArray(KGHConstant.cfsywangzhewq);
            String cfsywangzhewqValue = "";
            for (Object o : cfsywangzhewq) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    cfsywangzhewqValue += ","+jsonObject1.getString("option_value");
                }
            }
            String cfsywangzhewqString = null;
            if(StringUtils.isNotEmpty(cfsywangzhewqValue)) {
                cfsywangzhewqString = cfsywangzhewqValue.substring(1);
                kghAttribute6.setAttribute_id(116);
                kghAttribute6.setOption_value(cfsywangzhewqString);
            }
            //主武器
            JSONArray cfsyzhuwuqi = JSONObject.parseArray(KGHConstant.cfsyzhuwuqi);
            String cfsyzhuwuqiValue = "";
            for (Object o : cfsyzhuwuqi) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    cfsyzhuwuqiValue += ","+jsonObject1.getString("option_value");
                }
            }
            String cfsyzhuwuqiString = null;
            if(StringUtils.isNotEmpty(cfsyzhuwuqiValue)) {
                cfsyzhuwuqiString = cfsyzhuwuqiValue.substring(1);
                kghAttribute7.setAttribute_id(117);
                kghAttribute7.setOption_value(cfsyzhuwuqiString);
            }
            //副武器
            JSONArray cfsyfuwuqi = JSONObject.parseArray(KGHConstant.cfsyfuwuqi);
            String cfsyfuwuqiValue = "";
            for (Object o : cfsyfuwuqi) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    cfsyfuwuqiValue += ","+jsonObject1.getString("option_value");
                }
            }
            String cfsyfuwuqiString = null;
            if(StringUtils.isNotEmpty(cfsyfuwuqiValue)) {
                cfsyfuwuqiString = cfsyfuwuqiValue.substring(1);
                kghAttribute8.setAttribute_id(118);
                kghAttribute8.setOption_value(cfsyfuwuqiString);
            }
            //玩偶枪
            JSONArray cfsywanouqiang = JSONObject.parseArray(KGHConstant.cfsywanouqiang);
            String cfsywanouqiangValue = "";
            for (Object o : cfsywanouqiang) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    cfsywanouqiangValue += ","+jsonObject1.getString("option_value");
                }
            }
            String cfsywanouqiangString = null;
            if(StringUtils.isNotEmpty(cfsywanouqiangValue)) {
                cfsywanouqiangString = cfsywanouqiangValue.substring(1);
                kghAttribute9.setAttribute_id(119);
                kghAttribute9.setOption_value(cfsywanouqiangString);
            }
            //投掷武器
            JSONArray cfsytouzhiwuqi = JSONObject.parseArray(KGHConstant.cfsytouzhiwuqi);
            String cfsytouzhiwuqiValue = "";
            for (Object o : cfsytouzhiwuqi) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    cfsytouzhiwuqiValue += ","+jsonObject1.getString("option_value");
                }
            }
            String cfsytouzhiwuqiString = null;
            if(StringUtils.isNotEmpty(cfsytouzhiwuqiValue)) {
                cfsytouzhiwuqiString = cfsytouzhiwuqiValue.substring(1);
                kghAttribute10.setAttribute_id(120);
                kghAttribute10.setOption_value(cfsytouzhiwuqiString);
            }
            //近战武器
            JSONArray cfsyjinzhanwuqi = JSONObject.parseArray(KGHConstant.cfsyjinzhanwuqi);
            String cfsyjinzhanwuqiValue = "";
            for (Object o : cfsyjinzhanwuqi) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    cfsyjinzhanwuqiValue += ","+jsonObject1.getString("option_value");
                }
            }
            String cfsyjinzhanwuqiString = null;
            if(StringUtils.isNotEmpty(cfsyjinzhanwuqiValue)) {
                cfsyjinzhanwuqiString = cfsyjinzhanwuqiValue.substring(1);
                kghAttribute11.setAttribute_id(121);
                kghAttribute11.setOption_value(cfsyjinzhanwuqiString);
            }
            //音效/道具
            JSONArray cfsydaojuyinxiao = JSONObject.parseArray(KGHConstant.cfsydaojuyinxiao);
            String cfsydaojuyinxiaoValue = "";
            for (Object o : cfsydaojuyinxiao) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    cfsydaojuyinxiaoValue += ","+jsonObject1.getString("option_value");
                }
            }
            String cfsydaojuyinxiaoString = null;
            if(StringUtils.isNotEmpty(cfsydaojuyinxiaoValue)) {
                cfsydaojuyinxiaoString = cfsydaojuyinxiaoValue.substring(1);
                kghAttribute12.setAttribute_id(122);
                kghAttribute12.setOption_value(cfsydaojuyinxiaoString);
            }
            //稀有皮肤
            JSONArray cfsyxiyoupifu = JSONObject.parseArray(KGHConstant.cfsyxiyoupifu);
            String cfsyxiyoupifuValue = "";
            for (Object o : cfsyxiyoupifu) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    cfsyxiyoupifuValue += ","+jsonObject1.getString("option_value");
                }
            }
            String cfsyxiyoupifuString = null;
            if(StringUtils.isNotEmpty(cfsyxiyoupifuValue)) {
                cfsyxiyoupifuString = cfsyxiyoupifuValue.substring(1);
                kghAttribute13.setAttribute_id(123);
                kghAttribute13.setOption_value(cfsyxiyoupifuString);
            }
            //王者皮肤
            JSONArray cfsywzpifu = JSONObject.parseArray(KGHConstant.cfsywzpifu);
            String cfsywzpifuValue = "";
            for (Object o : cfsywzpifu) {
                JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(o));
                if(accountInfo.getDes().contains(jsonObject1.getString("option_name"))){
                    cfsywzpifuValue += ","+jsonObject1.getString("option_value");
                }
            }
            String cfsywzpifuString = null;
            if(StringUtils.isNotEmpty(cfsywzpifuValue)) {
                cfsywzpifuString = cfsywzpifuValue.substring(1);
                kghAttribute14.setAttribute_id(124);
                kghAttribute14.setOption_value(cfsywzpifuString);
            }
            //包人脸
            if(Objects.equals(LCConstant.bakFace,accountInfo.getLevel())){
                kghAttribute15.setAttribute_id(221);
                kghAttribute15.setOption_value("2");
            }else{
                kghAttribute15.setAttribute_id(221);
                kghAttribute15.setOption_value("3");
            }
            //无防沉迷
            kghAttribute16.setAttribute_id(230);
            kghAttribute16.setOption_value("3");
        }
        KghAttribute[] KghAttributes = {kghAttribute1,kghAttribute2,kghAttribute3,kghAttribute4,kghAttribute5,kghAttribute6,
                kghAttribute7,kghAttribute8,kghAttribute9,kghAttribute10,kghAttribute11,kghAttribute12,kghAttribute13,kghAttribute14,
                kghAttribute15,kghAttribute16,kghAttribute17,kghAttribute18,kghAttribute19,kghAttribute20,kghAttribute21,kghAttribute22,kghAttribute23};
        for(int i = 0;i<KghAttributes.length;i++){
            if(StringUtils.isNotEmpty(KghAttributes[i].getOption_value())){
                attributes.add(KghAttributes[i]);
            }
        }
        params.put("goods_attribute", attributes);
        return params;
    }


    @Override
    public AjaxResult delGame(Long id, Long userId,SalePartner salePartner) {
        this.salePartner = salePartner;
        Map<String, Object> canshu = new HashMap<>();
        String uuid = UUID.fastUUID().toString();
        String timestamp = String.valueOf(new Date().getTime()/1000);
        String md5 = DigestUtils.md5Hex(salePartner.getOther()+salePartner.getSaleKey()+timestamp+uuid).toUpperCase();
        canshu.put("x-kgh-token",salePartner.getOther());
        canshu.put("x-kgh-nonce",uuid);
        canshu.put("x-kgh-signature",md5);
        canshu.put("x-kgh-timestamp",timestamp);
        Map<String, Object> params = new HashMap<>();
        AccountInfo accountInfo = accountInfoMapper.selectAccountInfoById(id);
        if (StringUtils.isNotEmpty(accountInfo.getKangehaoid())){
            params.put("guid",Long.valueOf(accountInfo.getKangehaoid()));
        }else{
            Map<String, Object> result = new HashMap<>();

            result.put("code", 500);
            result.put("req", JSONObject.toJSONString(params));
            result.put("res", "无id");
            result.put("msg", "无id");
            return AjaxResult.success(result);
        }
        log.info("看个号删除接口请求参数={}", JSONObject.toJSONString(params));
        String response = HttpUtils.sendPostAddHeader(salePartner.getTwoOther()+"/removeGoods", JSONObject.toJSONString(params), canshu);
        if (StringUtils.isEmpty(response)) {
            throw new GlobalException("请求接口失败");
        }
        log.info("看个号删除接口返回参数={}", JSONObject.toJSONString(response));
        JSONObject resultJson = JSONObject.parseObject(response);
        Map<String, Object> result = new HashMap<>();

        if (!"200".equals(resultJson.getString("code"))) {
            result.put("code", 500);
        } else {
            result.put("code", 200);
        }

        result.put("req", JSONObject.toJSONString(params));
        result.put("res", response);
        result.put("msg", resultJson.getString("data"));
        return AjaxResult.success(result);
    }


    public static void main(String[] args){
        Map<String, Object> params = new HashMap<>();
        params.put("x-kgh-token","2023022452790594");
        params.put("x-kgh-nonce",UUID.fastUUID().toString());
        params.put("x-kgh-signature",DigestUtils.md5Hex("2023022452790594"+"f220a3b4619e39cbc40c5f1f1c7b6344"+new Date().getTime()/1000+""+UUID.fastUUID().toString()).toUpperCase());
        params.put("x-kgh-timestamp",String.valueOf(new Date().getTime()/1000));
        String response = HttpUtils.sendPost("https://test.kangehao.com/login",JSONObject.toJSONString(params),"application/json");
        System.out.println(response);
    }

}
